Skip to content

Validate converted HTTP/2 headers and trailers#2275

Merged
hyperxpro merged 3 commits into
AsyncHttpClient:mainfrom
maygemdev:perf/http2-response-header-validation
Jul 25, 2026
Merged

Validate converted HTTP/2 headers and trailers#2275
hyperxpro merged 3 commits into
AsyncHttpClient:mainfrom
maygemdev:perf/http2-response-header-validation

Conversation

@pavel-ptashyts

@pavel-ptashyts pavel-ptashyts commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • retain complete HTTP token and value validation when converting HTTP/2 response headers and trailers
  • drop the trailer-prohibited fields (Content-Length, Transfer-Encoding, Trailer) instead of rejecting them
  • centralize pseudo-header filtering without a per-frame capturing lambda
  • cover malformed names and values, empty names, and prohibited trailer fields

Motivation

The original implementation assumed the HTTP/2 decoder had already performed complete header-name validation. Netty 4.2.15 validates HTTP/2 casing and pseudo-header rules, but it does not enforce the complete HTTP token syntax, and decoded values are not validated by default. Disabling name validation therefore removed the only complete check before headers reached user code.

This revision keeps Netty's normal header validation on both the response and trailer paths, so names are token-checked and values are CR/LF-checked exactly as they were before.

Trailers additionally drop the fields that cannot be processed after the content, matching HttpObjectDecoder.isPermittedTrailingHeader. Dropping rather than rejecting is deliberate. RFC 9110 section 6.5.1 puts the constraint on the sender, and the only recipient-level requirement in that section concerns merging trailers into the header section, which this code does not do. Rejecting would also fail a response whose body has already been delivered to the AsyncHandler, and would make HTTP/2 behave differently from HTTP/1 for the same server response, since HttpObjectDecoder drops these fields silently.

The shared enhanced-for copy path avoids a capturing lambda allocation for each response and trailer frame.

Validation

  • JDK 11 focused Http2HandlerTest: 5 tests passed
  • JDK 11 ./mvnw clean verify: build, tests, Javadocs, signing, and Revapi passed

Attribution

Codex on behalf of Pavel Ptashyt

HTTP/2 decoding already validates response header names. Rechecking them
while converting to HttpHeaders repeats per-character work for every
response and trailer.

Use a factory that disables only name validation while preserving value
validation, including CR/LF rejection. Cover both properties with focused
tests.

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.com>
Comment thread client/src/main/java/org/asynchttpclient/netty/handler/Http2Handler.java Outdated
Comment thread client/src/main/java/org/asynchttpclient/netty/handler/Http2Handler.java Outdated
Comment thread client/src/main/java/org/asynchttpclient/netty/handler/Http2Handler.java Outdated
Comment thread client/src/main/java/org/asynchttpclient/netty/handler/Http2Handler.java Outdated
Comment thread client/src/main/java/org/asynchttpclient/netty/handler/Http2Handler.java Outdated
Comment thread client/src/test/java/org/asynchttpclient/netty/handler/Http2HandlerTest.java Outdated
Comment thread client/src/test/java/org/asynchttpclient/netty/handler/Http2HandlerTest.java Outdated
Restore complete HTTP token and value validation when converting decoded
HTTP/2 headers. Use Netty's trailer-specific factory so prohibited
trailing fields cannot reach handlers.

Replace capturing copy lambdas with enhanced loops and cover malformed
names, values, empty names, and prohibited trailers.

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.com>
@pavel-ptashyts pavel-ptashyts changed the title Avoid redundant HTTP/2 header name validation Validate converted HTTP/2 headers and trailers Jul 25, 2026
@pavel-ptashyts

Copy link
Copy Markdown
Contributor Author

Addressed all review feedback in 0411239:

  • restored complete response-header name and value validation
  • applied trailer-specific restrictions
  • replaced the capturing copy lambda with an enhanced for loop
  • added coverage for malformed and empty names, malformed values, and prohibited trailers
  • corrected the PR title and description to reflect the revised scope

The focused tests and the full JDK 11 ./mvnw clean verify pass.

@pavel-ptashyts
pavel-ptashyts requested a review from hyperxpro July 25, 2026 13:44
Comment thread client/src/main/java/org/asynchttpclient/netty/handler/Http2Handler.java Outdated
Comment thread client/src/test/java/org/asynchttpclient/netty/handler/Http2HandlerTest.java Outdated
Preserve valid trailing headers when a peer sends fields that are
prohibited in trailers. Failing the stream at that point discards the
trailer section after the response body has already been delivered.

Keep full header name and value validation for both response headers and
trailers, and cover the distinct conversion rules.

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.com>
@pavel-ptashyts
pavel-ptashyts requested a review from hyperxpro July 25, 2026 18:34
@hyperxpro
hyperxpro merged commit 143eedc into AsyncHttpClient:main Jul 25, 2026
13 checks passed
@pavel-ptashyts
pavel-ptashyts deleted the perf/http2-response-header-validation branch July 26, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants